package com.nwpusp.display.views.components;

import com.example.petssports.R;
import com.nwpusp.display.GlobalVar;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;

public class Button extends View{
	public Bitmap btnBitmap = null;
	private Bitmap btnDownBitmap = null;
	public float x;
	public float y;
	public float scale;
	public int btnIndex;
	public float width;
	public float height;
	private boolean isDown = false;
	
	public Button(Context view,float scale,int btnIndex){
		super(view);
		this.scale = scale;
		this.btnIndex = btnIndex;
		getBitmapSource();
		btnBitmap = GlobalVar.VerticalScale(btnBitmap,scale);
		btnDownBitmap = GlobalVar.VerticalScale(btnDownBitmap,scale);
		width = btnBitmap.getWidth();
		height = btnBitmap.getHeight();
	}
	
	public void setLocation(float x ,float y){
		this.x = x;
		this.y = y;
	}
	
	private void getBitmapSource(){
		switch(btnIndex){
			case GlobalVar.SINGLE_PLAYER:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.single);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.single);
				break;
			}
			case GlobalVar.MULTI_PLAYER:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.multy);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.multy);
				break;
			}
			case GlobalVar.CREATE_GAME:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.create);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.create);
				break;
			}
			case GlobalVar.JOIN_GAME:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.join);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.join);
				break;
			}
			case GlobalVar.READY_GAME:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ready);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ready);
				break;
			}
			case GlobalVar.START_GAME:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.go);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.go);
				break;
			}
			case GlobalVar.PROPS_FANQIE:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fanqie);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fanqie_down);
				break;
			}
			case GlobalVar.PROPS_JIDAN:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.jidan);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.jidan_down);
				break;
			}
			case GlobalVar.PROPS_BIANBIAN:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bianbian);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bianbian_down);
				break;
			}
			case GlobalVar.ONCE_AGAIN:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.once_again);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.once_again_down);
				break;
			}
			case GlobalVar.BACK_TO_MAIN:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.back_tomain);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.back_tomain_down);
				break;
			}
			case GlobalVar.BACK:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.back);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.back);
				break;
			}
			case GlobalVar.CANCEL:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cancel);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cancel);
				break;
			}
			case GlobalVar.TRACK_DOWN:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.down);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.down);
				break;
			}
			case GlobalVar.TRACK_UP:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.up);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.up);
				break;
			}
			case GlobalVar.THROW:{
				btnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.throwprops);
				btnDownBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.throwprops);
				break;
			}
			default:break;
			
		}
	}
	
	public boolean isClick(float xl,float yl){
		if((xl>x) && (xl<x+width)&&(yl>y)&&(yl<y+height)){
			isDown = true;
			return true;
		}
		else
			return false;
	}
	
	public Bitmap draw(){
		if(!isDown){
			return btnBitmap;
		}
		else {
			isDown = false;
			return btnDownBitmap;	
		}
	}
	
	
}
